var path = require('path')
var webpack = require('webpack')
var autoprefixer = require('autoprefixer')
var precss       = require('precss')
var ExtractTextPlugin = require("extract-text-webpack-plugin")

var config = {
  devtool: 'source-map',
  entry: [
    'webpack-hot-middleware/client',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'src/static/'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),

    /*
    //https://webpack.github.io/docs/stylesheets.html
    new ExtractTextPlugin("bundle.css", {
         allChunks: true
    })
    */
  ],
  module: {
    /*
     http://babeljs.cn/docs/usage/babelrc/
     http://survivejs.com/webpack_react/webpack_and_react/
     可以不使用.babelrc,因为识别env环境变量需要配置系统，太不方便
    */
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
        query: {
          cacheDirectory: true,
          presets: ['react', 'es2015','react-hmre']
        },
        include: __dirname
      },
      {
        test:   /\.css$/,
        loader: "style-loader!css-loader!postcss-loader"
        //loader: ExtractTextPlugin.extract("style-loader","css-loader!postcss-loader"),
        //include: __dirname
      },
      //{test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'}
      //{test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192&name=images/[name].[ext]'}  
      { 
         test: /\.(png|jpg|gif)$/, 
         loader: 'file-loader?name=img/[name].[ext]'
      } 
       
    ]
  },
  postcss: function () {
     return [autoprefixer, precss];
  }
}

module.exports = config;